part of '../service.dart';

const _kEventIdKey = 'insert_id';
const _kEventTimeKey = 'time';
const _kEventTypeKey = 'event_type';
const _kEventUserIdKey = 'user_id';
const _kEventDeviceIdKey = 'device_id';
const _kEventPurchasedItemSkuKey = 'product_id';
const _kEventRevenueKey = 'revenue';

class _EventDto extends Equatable {
  const _EventDto._internal({
    required this.id,
    required this.timeDto,
    required this.typeDto,
    required this.userId,
    required this.deviceId,
    required this.purchaseItemSku,
    required this.revenue,
  });

  final String id;
  final _TimeDto timeDto;
  final _EventTypeDto typeDto;
  final String? userId;
  final String? deviceId;
  final String? purchaseItemSku;
  final double? revenue;

  @override
  List<Object?> get props {
    return [
      id,
      timeDto,
      typeDto,
      userId,
      deviceId,
      purchaseItemSku,
      revenue,
    ];
  }

  factory _EventDto.fromEntity(AmplitudeApiEvent event) {
    final timeDto = _TimeDto.fromEntity(event.time);
    final typeDto = _EventTypeDto.fromEntity(event.type);

    return _EventDto._internal(
      id: event.id,
      timeDto: timeDto,
      typeDto: typeDto,
      userId: event.userId,
      deviceId: event.deviceId,
      purchaseItemSku: event.purchaseItemSku,
      revenue: event.revenue,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      _kEventIdKey: id,
      _kEventTimeKey: timeDto.timeMs,
      _kEventTypeKey: typeDto.toString(),
      _kEventUserIdKey: userId,
      _kEventDeviceIdKey: deviceId,
      _kEventPurchasedItemSkuKey: purchaseItemSku,
      _kEventRevenueKey: revenue,
    };
  }
}
